<?php

/*
 * @author Ebrain Cedeno <ebraincedeno@gmail.com>
 */

class TLink extends TWidget{
    
    public $Href="#";
    public $Rel ="";
    public $Target ="";
    public $Type = "";
    public $Text='';
    
    //eventos
    
    public $onClick;
    public $ondbClick;
    
    public function __construct($label="Link") {
        parent::__construct(__CLASS__);
        $this->Text = $label;
    }
    
    protected function getTarget(){
        if ($this->Target != ""){
            return 'rel="'.$this->Rel.'"';
        }
    }
    
    protected function getType(){
        if ($this->Type != ""){
            return 'type="'.$this->Type.'"';
        }
    }
    
    protected function Onclick(){ //verifica el evento click y lo carga
        if ($this->onClick != ""){
            return '<script type="text/javascript">
                $(document).ready(function() {
                $("#'.$this->Id.'").click(function(event){
                    '.$this->onClick.'
                });
            });
            </script>'."\n";
        }
    }
    
    protected function OnDbClick(){ //verifica el evento doble click y lo carga
        if ($this->ondbClick != ""){
            return '<script type="text/javascript">
                $(document).ready(function() {
                $("#'.$this->Id.'").dbclick(function(event){
                    '.$this->ondbClick.'
                });
            });
            </script>'."\n";
        }
    }

    public function show(){
        if ($this->Visible == true){
            $link = '<a id="'.$this->Id.'" href="'.$this->Href.'" '.$this->getOptionsAditional().' '.$this->getTarget().' '.$this->Type.' >'.$this->Text.'</a>'."\n";
            $link .= $this->Onclick();
            $link .= $this->OnDbClick();
            return $link;
        }
    }
    
}
?>
